import React, { useEffect, useState } from 'react'

export default function App() {
  let [name, setName] = useState('张三')
  let [password, setPassword] = useState(123)
  const save = (e) => {
    e.preventDefault()
  }

  // function changeName(e) {
  //   setName(e.target.value)
  // }
  // function changePassword(e) {
  //   setPassword(e.target.value)
  // }

  function changeDate(e, fn) {
    fn(e.target.value)
  }
  useEffect(() => {
    console.log(name, password)
  }, [name, password])

  return (
    <div>
      <form onSubmit={save}>
        {/* <label>
          姓名:
          <input type="text" value={name} onChange={changeName} />
        </label>
        <br />
        <label>
          密码:
          <input type="password" value={password} onChange={changePassword} />
        </label> */}

        <label>
          姓名:
          <input
            type="text"
            value={name}
            onChange={(e) => changeDate(e,setName)}
          />
        </label>
        <br />
        <label>
          密码:
          <input
            type="password"
            value={password}
            onChange={(e) => changeDate(e,setPassword)}
          />
        </label>
        <br />
        <button>提交</button>
      </form>
    </div>
  )
}
